//
//  JAFCalenderYearCollectionViewCell.m
//  JAFDemo
//
//  Created by 阿飞 on 2018/1/26.
//  Copyright © 2018年 阿飞. All rights reserved.
//

#import "JAFCalenderYearCollectionViewCell.h"
#import "UIColor+Expanded.h"
#import "UIView+FTCornerdious.h"
@implementation JAFCalenderYearCollectionViewCell
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        _labelYearMonth = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
        _labelYearMonth.font = [UIFont systemFontOfSize:14];
        
        _labelYearMonth.textAlignment = NSTextAlignmentCenter;
        _labelYearMonth.userInteractionEnabled = YES;
        // [_label setTextColor:[UIColor colorWithRed:74/255.0 green:74/255.0 blue:74/255.0 alpha:1.0]];
        
        [self.contentView addSubview:_labelYearMonth];
    }
    return self;
    
}
-(void)setModel:(LXCalendarDayModel *)model{
    
    _model = model;
    
    self.labelYearMonth.text = [NSString stringWithFormat:@"%ld",model.totalMonth];
    
    [self.labelYearMonth setFTCornerdious:0.0];
    self.labelYearMonth.backgroundColor = [UIColor whiteColor];
    
    self.userInteractionEnabled = YES;
    
   // [self addAnimaiton];
    
    if (model.isSelected) {
        
        [self.labelYearMonth setFTCornerdious:self.labelYearMonth.frame.size.width/2];
        
        self.labelYearMonth.backgroundColor = model.selectBackColor?model.selectBackColor:[UIColor greenColor];

          if (model.isHaveAnimation) {

                [self addAnimaiton];

           }

        }
    self.labelYearMonth.textColor = model.currentMonthTitleColor?model.currentMonthTitleColor:[UIColor hexStringToColor:@"000000"];

            if (model.isToday) {

                self.labelYearMonth.textColor = model.todayTitleColor?model.todayTitleColor:[UIColor redColor];

            }

}
-(void)addAnimaiton{
    
    CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
    anim.values = @[@0.6,@1.2,@1.0];
    //    anim.fromValue = @0.6;
    anim.keyPath = @"transform.scale";  // transform.scale 表示长和宽都缩放
    anim.calculationMode = kCAAnimationPaced;
    anim.duration = 0.25;                // 设置动画执行时间
    //    anim.repeatCount = MAXFLOAT;        // MAXFLOAT 表示动画执行次数为无限次
    
    //    anim.autoreverses = YES;            // 控制动画反转 默认情况下动画从尺寸1到0的过程中是有动画的，但是从0到1的过程中是没有动画的，设置autoreverses属性可以让尺寸0到1也是有过程的
    
    [self.labelYearMonth.layer addAnimation:anim forKey:nil];
}

@end
